package LinkedList;

public class ListInversion {


    class ListNode{
        ListNode next;
        int data;
        ListNode(int data,ListNode node){
            this.data = data;
            this.next = node;
        }

    }

    //递归反转链表
    //从最后一个节点开始递归
    public static ListNode recursion(ListNode head){
        if(head == null || head.next == null){
            return head;
        }

        ListNode new_head = recursion(head.next);
        head.next.next = head;
        head.next = null;
        return new_head;
    }
}
